import pandas as pd
import tqdm
import logging as log
from oneapi.oneapi import OneApi

log.basicConfig(level=log.INFO, format='%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s')


base_url = "http://192.168.31.248:8000/v1"
#base_url = "http://192.168.31.205:30000/v1"
api_key="g01wN4cdCRIM3tjaEd788fC4CcF14734B989E677CaBe66C7-4"


client = OneApi(base_url=base_url, api_key=api_key)

def clean_data(file_path):
    df = pd.read_excel(file_path)
    # 循环读取每一行第一列,如果docker或者nas同时不在,则删除该行
    for index, row in tqdm(df.iterrows()):
        title = row.tolist()[0]
        if "docker" not in title and "nas" not in title:
            df.drop(index=index, inplace=True)
    df.to_excel(file_path, index=False)


def analyze_data(file_path):
    df = pd.read_excel(file_path)
    # 最后添加一列,用于存放结果
    df["结果"] = ""
    #model = "chatglm3_6b"
    model = "SparkDesk"
    #model = "gpt-3.5-turbo"
    # 循环每一行数据
    for index, row in df.iterrows():
        title = row.tolist()[0]
        log.info("开始分析: %s" % title)
        msg = "%s,请帮我提取出上述标题中的docker容器名称,格式严格控制为docker-名称,如果没有提供则返回空字符串,不要返回多余数据,不要返回换行符" % title
        msg = client.chatMsg(msg, model)
        log.info("分析结果: %s" % msg)
        df.loc[index, "结果"] = msg
        log.info("完成分析: %s" % title)
    df.to_excel(file_path, index=False)



if __name__ == "__main__":
    file_path = r"D:\\bilibili_20231121.xlsx"
    analyze_data(file_path)
